import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:jetour_line/utils/double_extension.dart';
import 'package:jetour_line/utils/extension_int.dart';

import '../my_colors.dart';

Future showMyDialog(
    context, content, leftTitle, rightTitle, Function callBack) {
  return showModalBottomSheet(
    backgroundColor: Colors.transparent,
    isScrollControlled: true,
    context: context,
    builder: (BuildContext context) {
      return Center(
        child: Container(
          margin: EdgeInsets.only(left: 60.px, right: 60.px),
          clipBehavior: Clip.antiAlias,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.all(Radius.circular(20.px)),
          ),
          width: double.infinity,
          height: 300.px,
          child: Padding(padding: EdgeInsets.only(left: 20.px,right: 20.px,),child: Column(
            children: [
              Container(
                alignment: Alignment.center,
                width: double.infinity,
                height: 190.px,
                child: Text(
                  content,
                  style: TextStyle(
                      fontWeight: FontWeight.bold,
                      fontSize: 16.0.px,
                      color: MyColors.color333333),
                ),
              ),
              Container(
                width: double.infinity,
                height: 0.5,
                color: MyColors.colorE1E1E1,
              ),
              Container(
                  width: double.infinity,
                  height: 100.px,
                  child: Row(
                    children: [
                      Expanded(
                          child: GestureDetector(
                              onTap: () {
                                callBack(0);
                                Navigator.pop(context);
                              },
                              child: Container(
                                  color: Colors.transparent,
                                  alignment: Alignment.center,
                                  child: Text(
                                    leftTitle,
                                    style: TextStyle(
                                        fontWeight: FontWeight.bold,
                                        fontSize: 16.0.px,
                                        color: MyColors.appColor),
                                  )))),
                      Container(width: 1.px,height: 60.px,color: MyColors.colorE1E1E1,),
                      Expanded(
                          child: GestureDetector(
                              onTap: () {
                                callBack(1);
                                Navigator.pop(context);
                              },
                              child: Container(
                                  color: Colors.transparent,
                                  alignment: Alignment.center,
                                  child: Text(
                                    rightTitle,
                                    style: TextStyle(
                                        fontWeight: FontWeight.bold,
                                        fontSize: 16.0.px,
                                        color: MyColors.colorred),
                                  ))))
                    ],
                  ))
            ],
          ),),
        ),
      );
    },
  );
}

Future showMyBottomSheet(context, List<String> options, Function function) {
  return showModalBottomSheet(
    backgroundColor: Colors.transparent,
    isScrollControlled: true,
    context: context,
    builder: (BuildContext context) {
      return Container(
        clipBehavior: Clip.antiAlias,
        decoration: const BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(20.0),
            topRight: Radius.circular(20.0),
          ),
        ),
        height: (options.length + 1) * 100.px + 20.px,
        child: Column(children: [
          SizedBox(
            height: 100.px,
            child: Stack(
              textDirection: TextDirection.rtl,
              children: [
                const Center(
                  child: Text(
                    '导航地图',
                    style:
                        TextStyle(fontWeight: FontWeight.bold, fontSize: 16.0),
                  ),
                ),
                IconButton(
                    icon: Icon(Icons.close),
                    onPressed: () {
                      Navigator.pop(context);
                    }),
              ],
            ),
          ),
          const Divider(height: 1.0),
          Expanded(
            child: ListView.builder(
              itemBuilder: (BuildContext context, int index) {
                return Container(
                  height: 100.px,
                  child: ListTile(
                      title: Text(options[index]),
                      onTap: () {
                        function(index);
                        Navigator.pop(context);
                      }),
                );
              },
              itemCount: options.length,
            ),
          ),
        ]),
      );
    },
  );
}

Future showBottomAlert(context, Widget widget) {
  return showModalBottomSheet(
    backgroundColor: Colors.transparent,
    isScrollControlled: true,
    context: context,
    builder: (BuildContext context) {
      return widget;
    },
  );
}